<?php
class NativeTableAction extends CommonAction {

    public function index()
    {
        $nativeCount = M('Native_count');
        $account = M('Enter_account');

        if(!isset($_GET['date']))
        {
            $week = date('w');
            if($week == 6)
                $date = date('Y-m-d', time() - 3600 * 24);
            else if($week == 0)
                $date = date('Y-m-d', time() - 3600 * 24 * 2);
            else
                $date = date('Y-m-d');
        }
        else
        {
            $date = $_GET['date'];
        }

        $accountData = $account->where("stuff_date='$date'")->select();

        $outCount = 0;
        foreach($accountData as $k=>$v)
        {
            $outCount += $v['stuff_count'];
        }

        $data = $nativeCount->where("date='$date'")->order('date desc')->select();

        $numberCount = 0;
        foreach($data as $k=>$v)
        {
            $numberCount += $v['number'];
        }

        $pay = M('Pay');
        $payData = $pay->field('native')->find();
        $nativePay = $payData['native'];

        $this->assign(
            array(
                'data' => $data,
                'date' => $date,
                'numberCount' => $numberCount,
                'nativePay' => $nativePay,
                'outCount' => $outCount,
            )
        );
        $this->display();
    }
}